package it.yuzuojian.com.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowCredentials(true);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //addResourceHandler是指你想在url请求的路径
        //addResourceLocations是图片存放的真实路径
        String pic = "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")
                +"music"+System.getProperty("file.separator")+"img"+ System.getProperty("file.separator");
        String song = "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+""
                +"music"+System.getProperty("file.separator")+"song"+ System.getProperty("file.separator");

        registry.addResourceHandler("/img/**").addResourceLocations(pic);
        registry.addResourceHandler("/song/**").addResourceLocations(song);
    }
}
